#include<stack>
#include<vector>

using namespace std;
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        stack<int> Push;
        stack<int> Pop;
        Push.push(pushed[0]);
        int j = 0;
        for (int i = 1; i < pushed.size(); i++) {
            while (!Push.empty() && Push.top() == popped[j]) {

                j++;
                Push.pop();
            }

            Push.push(pushed[i]);
        }
        while (!Push.empty() && Push.top() == popped[j]) {
            j++;
            Push.pop();
        }
        return Push.empty();
    }
};